package br.inf.solutions.apresentacoes.ssp.model.bulletin.items;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import br.com.vexillum.model.annotations.Validate;
import br.com.vexillum.util.SpringFactory;
import br.inf.solutions.apresentacoes.ssp.control.DispenseFunctionPersonController;
import br.inf.solutions.apresentacoes.ssp.model.Person;
import br.inf.solutions.apresentacoes.ssp.model.bulletin.BulletinItem;
import br.inf.solutions.apresentacoes.ssp.model.bulletin.BulletinTopics;
import br.inf.solutions.apresentacoes.ssp.model.interfaces.IExistsPerson;

@Entity
@SuppressWarnings("serial")
@Table(name = "dispense_function_person")
public class DispenseFunctionPerson extends BulletinItem implements IExistsPerson {

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "function_person_id", updatable = false)
	private FunctionPerson function;
	
	@Validate(notNull = false)
	@Column(name = "end_date", nullable = true, unique = false, updatable = true)
	private Date endDate;
	
	public DispenseFunctionPerson(FunctionPerson entity, Date endDate) {
		super(new BulletinTopics(4l, "DispenseFunctionPerson", "/paginas/funcao/dispensarRetificacao.zul"));
		this.function = entity;
		if(endDate==null)
			this.endDate = new Date();
		else
			this.endDate = endDate;
	}
	
	public DispenseFunctionPerson() {
		super(new BulletinTopics(4l, "DispenseFunctionPerson", "/paginas/funcao/dispensarRetificacao.zul"));
	}

	public FunctionPerson getFunction() {
		return function;
	}

	public void setFunction(FunctionPerson function) {
		this.function = function;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	@Override
	public DispenseFunctionPersonController getControl() {
		return SpringFactory.getController("dispenseFunctionPersonController", DispenseFunctionPersonController.class, null);
	}

	@Override
	public Person getPerson() {
		return getFunction() == null ? null : getFunction().getPerson();
	}

	@Override
	public void setPerson(Person person) {}

}
